package org.fujay.langchain4jserver.domain.model.vo;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.Arrays;
import java.util.Objects;

/**
 * 模型连接测试结果枚举
 */
@Getter
@RequiredArgsConstructor
public enum TestResult {
    UNTESTED(0, "未测试"),
    SUCCESS(1, "成功"),
    FAILED(2, "失败");

    private final int code;
    private final String description;

    /**
     * 根据代码获取枚举实例
     *
     * @param code 状态码 (0, 1, 2)
     * @return 对应的 TestResult 枚举，如果代码未知则返回 UNTESTED
     */
    public static TestResult fromCode(Integer code) {
        if (code == null) return UNTESTED;
        return Arrays.stream(values())
                .filter(v -> Objects.equals(v.code, code))
                .findFirst()
                .orElse(UNTESTED);
    }
}
